% File: sc_fde_ib_var_evolution.m
% -------------------------------
% This script simulates output variance vs. input SNR of soft detector.

% normmse = (.03: .0001: .13); % normalized mse input
% normvar; % normalized var output
snr_tmp = 1./normmse;
normvar_log = log10(normvar);

figure();
semilogx(normvar, snr_tmp);
set(gca,'XDir','reverse')
xlabel('Average Variance'); ylabel('SNR');
grid on
legend('Transfer Function of Soft Decision (Num. Int.)', 'Location', 'SouthEast');
title('VAR Evolution Chart');

figure();
semilogx(normvar, normmse);
set(gca,'XDir','reverse')
xlabel('Average Variance'); ylabel('MSE');
grid on
legend('Transfer Function of Soft Decision (Num. Int.)', 'Location', 'NorthEast');
title('VAR Evolution Chart');

% soft-dec curve fitting coefficients
switch M_mod
    case 4
        a_cf = -.3024;
        b_cf = -.9306;
        c_cf = -.04903;
        % var = 10^(a_cf * mse^b_cf + c_cf)
    case 8
        a_cf = -.1555;
        b_cf = -.8582;
        c_cf = -.2447;
        % var = 10^(a_cf * mse^b_cf + c_cf)
    case 16
        a_cf = -.1517;
        b_cf = -.7809;
        c_cf = -.1978;
        % var = 10^(a_cf * mse^b_cf + c_cf)
    case 32
%         a_cf = -.1655;
%         b_cf = -.6745;
%         c_cf = -.2145;
        a_cf = -0.03295;
        b_cf = -0.942;
        c_cf = -0.8841;
        % var = 10^(a_cf * mse^b_cf + c_cf)
    case 64
        a_cf = -0.01537;
        b_cf = -0.951;
        c_cf = -1.206;
        % var = 10^(a_cf * mse^b_cf + c_cf)
    otherwise
        % no def.
end

var_soft_test = 10.^(a_cf * normmse.^b_cf + c_cf);

figure();
semilogx(var_soft_test, snr_tmp);
set(gca,'XDir','reverse')
xlabel('Average Variance'); ylabel('SNR');
grid on
legend('Transfer Function of Soft Decision (Curv. Fit.)', 'Location', 'SouthEast');
title('VAR Evolution Chart');

figure();
semilogx(var_soft_test, normmse);
set(gca,'XDir','reverse')
xlabel('Average Variance'); ylabel('MSE');
grid on
legend('Transfer Function of Soft Decision (Num. Int.)', 'Location', 'NorthEast');
title('VAR Evolution Chart');

% % mse_tmp % mse output of equalizer, as an input to the soft detector
% % evaluation function var_tmp = f(mse_tmp)
% H_tmp  = squeeze(H).';
% H_tmp  = reshape(H_tmp,[],nt);
% %% SNR evolution characteristic
% snr_in    = SNR(n);
% npow_norm = noisePow_norm;
% 
% var_tmp   = .0001*(10000: -1: 1);
% mu_tmp    = zeros(size(var_tmp));
% for n_var = 1: length(var_tmp)
%     mu_tmp(n_var) = mean(abs(H_tmp).^2./(var_tmp(n_var).*abs(H_tmp).^2+npow_norm));
% end
% mse_tmp   = xtxPower_mean*(1./mu_tmp - var_tmp);
% sinr_tmp  = 1./mse_tmp;
% 
% figure();
% semilogx(var_tmp, sinr_tmp);
% set(gca,'XDir','reverse')
% xlabel('Average Variance'); ylabel('SNR');
% grid on
% legend('Transfer Function of Equalizer', 'Location', 'SouthEast');
% title('SNR Evolution Chart');
% 
% figure();
% semilogx(var_tmp, mse_tmp);
% set(gca,'XDir','reverse')
% xlabel('Average Variance'); ylabel('MSE');
% grid on
% legend('Transfer Function of Equalizer', 'Location', 'SouthEast');
% title('MSE Evolution Chart');

% End of script